package com.lovo.roomProject.room.dao.impl;

import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.RoomDO;
import com.lovo.roomProject.pojo.StudentDO;
import com.lovo.roomProject.room.dao.RoomDAO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomDAOImpl extends BaseDAO implements RoomDAO {
    @Override
    public List listRoom() {
        this.getConnection();
        String sql="\n" +
                "SELECT r_addr,r_count,r_status,count(s_r_id) as 已住人数,r_type from t_student s left join t_room r on s.s_r_id=r.r_id GROUP BY r_addr";
        List list =new ArrayList();
        try {
            statement=con.prepareStatement(sql);
            rs=statement.executeQuery();
            while (rs.next()){
                RoomDO roomDO=new RoomDO();
                roomDO.setAddr(rs.getString("r_addr"));
                roomDO.setCount(rs.getInt("r_count"));
                roomDO.setStatus(rs.getString("r_status"));
                roomDO.setType(rs.getString("r_type"));
                roomDO.setInCount(rs.getInt("已住人数"));
                list.add(roomDO);

            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return list;
    }
}
